package com.ibm.workplace.wcm.cqplugin.ui.preference;

import java.util.*;

import org.eclipse.jface.preference.*;
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import com.ibm.workplace.wcm.cqplugin.preference.*;

public class CqQueryColumnsComposites extends Composite {
    
    private Set fields;

    public CqQueryColumnsComposites(Composite parent, int style) {
        super(parent, style);
        
        GridLayout layout = new GridLayout(2, false);
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        setLayout(layout);
        
        fields = new HashSet();
        
        /*
         *         store.setDefault(CmvcPreferenceConstants.PREF_DEFECT_NAME_COLUMN, "name");
        store.setDefault(CmvcPreferenceConstants.PREF_ABSTRACT_COLUMN, "abstract");
        store.setDefault(CmvcPreferenceConstants.PREF_COMPONENT_COLUMN, "compname");
        store.setDefault(CmvcPreferenceConstants.PREF_RELEASE_COLUMN, "releaseName");
        store.setDefault(CmvcPreferenceConstants.PREF_OWNER_COLUMN, "ownerlogin");
        store.setDefault(CmvcPreferenceConstants.PREF_ORIGINATOR_COLUMN, "originlogin");
        store.setDefault(CmvcPreferenceConstants.PREF_STATE_COLUMN, "state");
        store.setDefault(CmvcPreferenceConstants.PREF_PRIORITY_COLUMN, "priority");
        store.setDefault(CmvcPreferenceConstants.PREF_TARGET_COLUMN, "target");
        store.setDefault(CmvcPreferenceConstants.PREF_SEVERITY_COLUMN, "severity");

         */
        createField("Defect number:", CqPreferenceConstants.PREF_DEFECT_NAME_COLUMN);
        createField("Abstract:", CqPreferenceConstants.PREF_ABSTRACT_COLUMN);
        createField("Component:", CqPreferenceConstants.PREF_COMPONENT_COLUMN);
        createField("Release:", CqPreferenceConstants.PREF_RELEASE_COLUMN);
        createField("Owner:", CqPreferenceConstants.PREF_OWNER_COLUMN);
        createField("Originator:", CqPreferenceConstants.PREF_ORIGINATOR_COLUMN);
        createField("State:", CqPreferenceConstants.PREF_STATE_COLUMN);
        createField("Priority:", CqPreferenceConstants.PREF_PRIORITY_COLUMN);
        createField("Target:", CqPreferenceConstants.PREF_TARGET_COLUMN);
        createField("Severity:", CqPreferenceConstants.PREF_SEVERITY_COLUMN);
    }

    private void createField(String caption, String preferenceName) {
        Label label = new Label(this, 0);
        label.setText(caption);
        
        Text text = new Text(this, SWT.BORDER);
        text.setData(preferenceName);
        GridData data = new GridData();
        data.widthHint = 100;
        text.setLayoutData(data);
        
        fields.add(text);
    }
    
    public void init(IPreferenceStore store) {
        for (Iterator it = fields.iterator(); it.hasNext(); ) {
            Text text = (Text)it.next();
            String preferenceName = (String)text.getData();
            text.setText(store.getString(preferenceName));
        }
    }
    
    public void store(IPreferenceStore store) {
        for (Iterator it = fields.iterator(); it.hasNext(); ) {
            Text text = (Text)it.next();
            String preferenceName = (String)text.getData();
            store.setValue(preferenceName, text.getText());
        }        
    }

}
